package eerbaar.client.internal.ctr.operator.area;

import eerbaar.extension.IExtensible;

class Value implements IValue {

    private double negativeValue;
    private double positiveValue;

    public Value() {
        //
    }

    public Value(double negativeValue, double positiveValue) {
        this.negativeValue = negativeValue;
        this.positiveValue = positiveValue;
    }

    @Override
    public IExtensible copy() {
        return new Value(this.negativeValue, this.positiveValue);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T extends IExtensible> T getExtension(Class<T> type) {

        if (type == IValue.class) {
            return (T) this;
        }

        return null;
    }

    @Override
    public double getNegativeValue() {
        return this.negativeValue;
    }

    @Override
    public double getPositiveValue() {
        return this.positiveValue;
    }

    @Override
    public double getValue() {
        return this.negativeValue + this.positiveValue;
    }

    @Override
    public void set(double value) {
        this.negativeValue = value;
        this.positiveValue = value;
    }

    @Override
    public void setIfGreaterThan(double value) {
        if (value > this.positiveValue) {
            this.positiveValue = value;
        }
    }

    @Override
    public void setIfLessThan(double value) {
        if (value < this.negativeValue) {
            this.negativeValue = value;
        }
    }

}
